package com.tjsinfo.tjsoa.workplan.action;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.DateTimeFromConver;
import com.tjsinfo.tjsoa.common.TestRiQi;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.workplan.bo.IWorkPlanMainBo;
import com.tjsinfo.tjsoa.workplan.vo.WorkPlanMain;

public class WorkPlanMonthModleUp extends Action{
	protected IWorkPlanMainBo workPlanMainBo;

	/**
	 * @return the workPlanMainBo
	 */
	public IWorkPlanMainBo getWorkPlanMainBo() {
		return workPlanMainBo;
	}

	/**
	 * @param workPlanMainBo the workPlanMainBo to set
	 */
	public void setWorkPlanMainBo(IWorkPlanMainBo workPlanMainBo) {
		this.workPlanMainBo = workPlanMainBo;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		User user = getUser(request);
		Date date = getDate(request);
		Map<Integer, WorkPlanMain> map = selectWork("M", user, date);
		return forword(mapping, request, date, map);
	}
   /**
    * 转发
    * @param mapping
    * @param request
    * @param date
    * @param map
    * @return
    */ 
   
	protected ActionForward forword(ActionMapping mapping,
			HttpServletRequest request, Date date, Map<Integer, WorkPlanMain> map) {
		request.setAttribute("yueli", date);
		request.setAttribute("map", map);
		
		return mapping.findForward("ok");
	}
   /**
    * 查询
    * @param user
    * @param date
    * @return
    */
	protected Map<Integer, WorkPlanMain> selectWork(String type,User user, Date date) {
		Map<Integer, WorkPlanMain> map = workPlanMainBo.selectWorkPlanTypeAndYearMAPNumber(type, 1900+date.getYear(), user.getUser_id());
		return map;
	}

	protected User getUser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		return user;
	}

	protected Date getDate(HttpServletRequest request) {
		String datestr = request.getParameter("date");
		Date date =	DateTimeFromConver.datetostr(datestr);
		date =	TestRiQi.upYear(date);
		return date;
	}
}
